package com.ruoyi.business.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.business.domain.OfficeBuildingRent;
import com.ruoyi.business.service.IOfficeBuildingRentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 写字楼出租Controller
 * 
 * @author ruoyi
 * @date 2025-09-12
 */
@RestController
@RequestMapping("/rent")
public class OfficeBuildingRentController extends BaseController
{
    @Autowired
    private IOfficeBuildingRentService officeBuildingRentService;

    /**
     * 查询写字楼出租列表
     */
    @RequiresPermissions("business:rent:list")
    @GetMapping("/list")
    public TableDataInfo list(OfficeBuildingRent officeBuildingRent)
    {
        startPage();
        List<OfficeBuildingRent> list = officeBuildingRentService.selectOfficeBuildingRentList(officeBuildingRent);
        return getDataTable(list);
    }

    /**
     * 导出写字楼出租列表
     */
    @RequiresPermissions("business:rent:export")
    @Log(title = "写字楼出租", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OfficeBuildingRent officeBuildingRent)
    {
        List<OfficeBuildingRent> list = officeBuildingRentService.selectOfficeBuildingRentList(officeBuildingRent);
        ExcelUtil<OfficeBuildingRent> util = new ExcelUtil<OfficeBuildingRent>(OfficeBuildingRent.class);
        util.exportExcel(response, list, "写字楼出租数据");
    }

    /**
     * 获取写字楼出租详细信息
     */
    @RequiresPermissions("business:rent:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(officeBuildingRentService.selectOfficeBuildingRentById(id));
    }

    /**
     * 新增写字楼出租
     */
    @RequiresPermissions("business:rent:add")
    @Log(title = "写字楼出租", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OfficeBuildingRent officeBuildingRent)
    {
        return toAjax(officeBuildingRentService.insertOfficeBuildingRent(officeBuildingRent));
    }

    /**
     * 修改写字楼出租
     */
    @RequiresPermissions("business:rent:edit")
    @Log(title = "写字楼出租", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OfficeBuildingRent officeBuildingRent)
    {
        return toAjax(officeBuildingRentService.updateOfficeBuildingRent(officeBuildingRent));
    }

    /**
     * 删除写字楼出租
     */
    @RequiresPermissions("business:rent:remove")
    @Log(title = "写字楼出租", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(officeBuildingRentService.deleteOfficeBuildingRentByIds(ids));
    }
}
